﻿#region

using System.Collections.Generic;
using System.Net;
using System.Text;

#endregion

namespace Minion.Win.Client.Helper
{
    public static class UrlHelper
    {
        public static string AddToQueryString(this string url, string name, string value)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(value))
                return url;

            var nameValueCollection = new Dictionary<string, string>();
            var stringBuilder = new StringBuilder(url);
            var str1 = url.Contains("?") ? "&" : "?";
            if (name.ToUpper().Equals("TARGET") && value.Length > 2048)
                value = string.Empty;
            nameValueCollection.Add(name, value);
            foreach (var item in nameValueCollection)
            {
                stringBuilder.AppendFormat("{0}{1}={2}", (object) str1, (object) HttpUtility.UrlEncode(item.Key),
                                           (object) HttpUtility.UrlEncode(item.Value));
                str1 = "&";
            }
            return (stringBuilder).ToString();
        }
    }
}